/**   
* @Title: GenerateCodeUtil.java 
* @Package com.ninelephas.whale.util 
* @Description: GenerateCodeUtil
* @author 杨智刚
* @date 2016年11月3日 上午11:13:59 
* @version V1.0   
*/
package com.warrior.util;

import java.util.Random;

/** 
* @ClassName: GenerateCodeUtil 
* @Description: 生成随机验证码
* @author 杨智刚
* @date 2016年11月3日 上午11:13:59 
*  
*/
public class GenerateCodeUtil {
    
    private GenerateCodeUtil() {
        throw new IllegalAccessError("Utility class");
      }
    
    /**
     * 
    * @Title: randomString 
    * @Description: 生成随机String验证码
    * @param @param length
    * @param @return    设定文件 
    * @return String    返回类型 
    * @author 杨智刚
    * @throws
     */
    public static final String randomString(int length) {
        char[] numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz"
                + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
        if (length < 1) {
            return "";
        }
        Random randGen = new Random();
        char[] randBuffer = new char[length];
        for (int i = 0; i < randBuffer.length; i++) {
            randBuffer[i] = numbersAndLetters[randGen.nextInt(71)];
        }
        return new String(randBuffer);
    }

    /**
     * 
    * @Title: randomInt 
    * @Description: 生成随机数字验证码
    * @param @param length
    * @param @return    设定文件 
    * @return String    返回类型 
    * @author 杨智刚
    * @throws
     */
    public static final String randomInt(int length) {
        if (length < 1) {
            return null;
        }
        Random randGen = new Random();
        char[] numbersAndLetters = ("0123456789").toCharArray();

        char[] randBuffer = new char[length];
        for (int i = 0; i < randBuffer.length; i++) {
            randBuffer[i] = numbersAndLetters[randGen.nextInt(10)];
        }
        return new String(randBuffer);
    }
}
